package com.gdziarmaga.webshop.author.services;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.gdziarmaga.webshop.author.model.Author;
import com.gdziarmaga.webshop.author.model.AuthorDAO;
import com.gdziarmaga.webshop.book.model.Book;
import com.gdziarmaga.webshop.book.model.BookDAO;
import com.gdziarmaga.webshop.utils.filtering.BaseFilter;

@Service("authorManager")
@Transactional(propagation = Propagation.REQUIRED, readOnly = false)
public class AuthorManagerImpl implements AuthorManager {

	@Autowired
	private AuthorDAO authorDAO;

	@Override
	public Author getAuthorById(Long authorId) {
		return authorDAO.getById(authorId);
	}

	@Override
	public Author getAuthorByAuthor_first_name(String first_name) {
		return authorDAO.findProductByAuthor_first_name(first_name);
	}

	@Override
	public Author getAuthorByAuthor_last_name(String last_name) {
		return authorDAO.findProductByAuthor_last_name(last_name);
	}

	@Override
		public void saveAuthor(Author author) {
		authorDAO.save(author);			
		}

	@Override
	public List<Author> getAll() {
		return authorDAO.getAll();
	}

	@Override
	public List<Author> getAuthorByFilter(BaseFilter baseFilter) {
		return authorDAO.getAll(baseFilter);
	}

}
